<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script th:src="@{/}+'js/tool.js'"></script>
    <style type="text/css">
        .layui-form .layui-form-item{
            width:90%;
        }
        .layui-input-inline{
            width:350px!important
        }
    </style>

</head>
<body style="margin-top: 100px">
<form class="layui-form" lay-filter="myform" id="myform">
    <input type="hidden" name="delFlag" id="delFlag" value="1">
    <input type="hidden" name="id" id="id" th:value="${id}">
    <input type="hidden" name="recordId" id="recordId">
    <input type="hidden" name="libId" th:value="${libId}">
    <input type="hidden" name="libQuestionId" th:value="${libQuestionId}">
    <div class="layui-form-item">
        <label class="layui-form-label">题干</label>
        <div class="layui-input-block">
            <textarea id="xxwb" name="xxwb"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">索引</label>
        <div class="layui-input-block">
            <input type="radio" name="indexLetter" value="1" title="1">
            <input type="radio" name="indexLetter" value="2" title="2">
            <input type="radio" name="indexLetter" value="3" title="3">
            <input type="radio" name="indexLetter" value="4" title="4">
            <input type="radio" name="indexLetter" value="5" title="5">
            <input type="radio" name="indexLetter" value="6" title="6">
            <input type="radio" name="indexLetter" value="7" title="7">
            <input type="radio" name="indexLetter" value="8" title="8">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">答案说明</label>
        <div class="layui-input-block">
            <textarea id="dasm" name="dasm"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">解析</label>
        <div class="layui-input-block">
            <textarea id="jiexi" name="jiexi"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">登记时间</label>
        <div class="layui-input-inline">
            <input type="text" name="createTime" id="createTime" th:value="${currentTime}" readonly="readonly" class="layui-input">
        </div>
    </div>
    <button id="submitBtn" class="layui-btn" style="display:none" lay-submit lay-filter="submitme">保存</button>
</form>
<script src="js/editor/ckeditor.js"></script>
<script src="js/editor/config.js"></script>
<script>
    var id = $("#id").val();
    CKEDITOR.replace('xxwb',
        {
            filebrowserImageUploadUrl: "uploadImage/upload?winname=choicewin",
            height: 150
        });
    CKEDITOR.replace('dasm',
        {
            filebrowserImageUploadUrl: "uploadImage/upload?winname=choicewin",
            height: 150
        });
    CKEDITOR.replace('jiexi',
        {
            filebrowserImageUploadUrl: "uploadImage/upload?winname=choicewin",
            height: 150
        });
    layui.use(['form', 'table', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer;
        form.on('submit(submitme)', function(data){
            var text = CKEDITOR.instances.xxwb.getData();
            // text = substractText(text);
            if(text.length<1){
                top.layer.msg("选项文本字数不能小于1");
                return false
            }
            var dasm = CKEDITOR.instances.dasm.getData();
            // dasm = substractText(dasm);
            var jiexi = CKEDITOR.instances.jiexi.getData();
            // jiexi = substractText(jiexi);
            var values = {text:text,answerText:dasm,analysis:jiexi};
            $(":input").each(function(i,v){
                if(v.name)
                    values[v.name] = v.value;

            })
            if(!values.id){
                delete values.id;
            }
            let ic = $(":radio[name=indexLetter]:checked");
            if(ic.length===0){
                layer.msg("请选择索引");
                return false;
            }
            values["indexLetter"] = ic.val();
            axios.post("libChoice/save",values).then(res=>{
                if(res.data.code==1){
                    layer.msg(ret.data.msg);
                }else{
                    var win = getTabWin("editwin");
                    win.loadGrid('main-table');
                    layer.msg("保存成功");
                    var index = top.layer.getFrameIndex(window.name);
                    top.layer.close(index);
                }
            })
            return false;
        });
        if(id){
            loadData()
        }
        function loadData(){
            var entity = getEntityInfo(id,"libChoice/getById");
            form.val("myform",entity);
            CKEDITOR.instances.xxwb.setData(entity.text);
            CKEDITOR.instances.dasm.setData(entity.answerText);
            CKEDITOR.instances.jiexi.setData(entity.analysis);
            if(entity.right!==1){
                $(":checkbox[name=right]").prop("checked",false);
                form.render();
            }

        }

    })
</script>
</body>
</html>

</body>
</html>